package com.wh.router;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ReturnListener;
import com.wh.utils.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Auther: HuiEr
 * @Date: 2020/3/11 21:23
 * @Description
 */
public class Producer {
    private static final String EXCHANGE_NAME="router_exchange";
    private static final String EXCHANGE_TYPE="direct";
    private static final String ROUTER_KEY_1="wang";
    private static final String ROUTER_KEY_2="hui";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = ConnectionUtil.getConnection().createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME,EXCHANGE_TYPE);
        for (int i=0;i<100;i++){
            if(i%2==0){
                channel.basicPublish(EXCHANGE_NAME,ROUTER_KEY_1,null,("路由模型生产者发送的消息  "+i).getBytes());
            }else {
                channel.basicPublish(EXCHANGE_NAME,ROUTER_KEY_2,null,("路由模型生产者发送的消息  "+i).getBytes());
            }
        }
    }
}
